#ifndef SPI_DEV_CTL_H_
#define SPI_DEV_CTL_H_

#include <stdint.h>
#include <stdbool.h>

typedef struct spi_config
{
    int spi_mode;      // [0-3]  (-1 when not configured).
    int lsb_first;     // {0,1}  (-1 when not configured).
    int bits_per_word; // [7...] (-1 when not configured).
    int spi_speed;     // 0 when not configured.
    int spi_ready;     // {0,1}  (-1 when not configured).
} spi_config_t;

typedef struct spi_dev_s
{
    bool dp_en; // debug print
    int fd;
    spi_config_t cfg;

    /** spi 初始化函数.
     * @param
     * @return
     * !程序结束之前需要关闭文件
     */
    int (*open)(void);

    /** spi 发送接收函数.
     * @param tx_date data will be sended.
     * @param rx_data data will reseived.
     * @param len data Lelngth(Byte).
     * @return success, 0 is returned.
     * 	error,  -1 is returned.
     */
    int (*transfer)(const uint8_t tx[], uint8_t rx[], uint32_t len);

    /** spi 设备文件关闭函数.
     * @param
     * @return
     */
    void (*close)(void);
} spi_dev_t;

#endif
